// pages/energy/energy.js
const app = getApp()
const WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.imgurl,
    ranking:[
      
    ],
    searchlist:[],
    searchtxt:''
  },
  // navTo: function (e) {
  //   var id = e.currentTarget.dataset.id;
  //   wx.navigateTo({
  //     url: '../detailse/index?babyid=' + e.currentTarget.dataset.id,
  //   })
  // },
  start_ranking(e){
    var id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '../rankingDeil/rankingDeil?babyid=' + id,
    })
  },
  click:function(){
    let that = this;
    var data = that.data.searchlist;
    if(data.length == 0){
      wx.showToast({
        title: '请输入宝贝姓名，以宝贝的名义为“小天鹅之夜”共筹能量种子',
        icon:'none',
        mask:true
      });
      return false;
    }
    if(data.length == 1){
      app.navTo('/pages/rankingDeil/rankingDeil?babyid=' + that.data.searchlist[0].id)
    }
  },
  //能量种子排行榜
  getenergyseed() {
    let that = this;
    app.request({
      url: 'index/energy_seed/SeedDonorList',
      method: 'get',
      data: {
        
      },
      success: function (res) {
        console.log(res)
        that.setData({
          ranking: res.data
        })
      }
    })
  },
  searchtxt:function(e){
    this.setData({
      searchtxt: e.detail.value
    })
  },
  // 搜索
  search(e) {
    let that = this;
    if (that.data.searchtxt == ''){
      wx.showToast({
        title: '请输入孩子姓名',
        icon: 'none'
      })
      return false;
    }
    app.request({
      url: 'index/energy_seed/EnergySearch',
      method: 'post',
      // type: 0,
      data: {
        key: that.data.searchtxt
      },
      success: function (res) {
        console.log(res)
        if (res.data.length == 0){
          wx.showToast({
            title: '暂无孩子信息',
            icon: 'none'
          })
        }else{
          that.setData({
            searchlist: res.data,
          })
        }

      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    app.request({
      url: 'index/energy_seed/energy_passageway',
      method: 'post',
      type: 0,
      success: function (res) {
        WxParse.wxParse('article', 'html', res.data.energy_passageway, that, 5)
      }
    })
    //能量种子排行
    //console.log(app.tabbarindex,'----index架子啊')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getenergyseed()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})